﻿using System;
using System.Collections.Generic;
using DynaPrecision.Numerical.Quadrature;

namespace DynaPrecision
{
	public static class EMIGaussQuadrature
	{
		public static T EvaluateFromPoint<T>(this IGaussQuadrature<T, T> evaluator, IList<T> from)
		{
			if (from.Count > evaluator.Weights.Count)
			{
				throw new Exception("The number of points input is larger than the evaluator's permitted order");
			}
			T result = DefaultValueProvider<T>.Zero;
			for (int i = 0; i < evaluator.Weights.Count; i++)
			{
				result += (dynamic)evaluator.Weights[i] * from[i];
			}
			return result;
		}
		public static T EvaluateIntegral<T>(this IGaussQuadrature<T, T> evaluator, Func<T, T> functor)
		{
			T result = DefaultValueProvider<T>.Zero;
			for (int i = 0; i < evaluator.Weights.Count; i++)
			{
				result += (dynamic)evaluator.Weights[i] * functor(evaluator.Nodes[i]);
			}
			return result;
		}
	}
}
